# 导包
import config
from API.login import LoginAPI
from API.course import CourseAPI
from API.contract import ContractAPI
# 创建测试类

class TestContractBusiness:
    # 初始化

    token=None
    filename=None
    courseId=None
    # 前置处理
    def setup_method(self):
        #实例化接口
        self.login_api=LoginAPI()
        self.course_api=CourseAPI()
        self.contract_api=ContractAPI()
    # 后置处理
    def teardown(self):
        pass
    # 1登录成功
    def test01_login_success(self):
        #获取验证码

        res_v=self.login_api.get_verify_code()
        print(res_v.status_code)
        print(res_v.json())
        #提取登陆需要的uuid
        uuid=res_v.json()["uuid"]
        print(uuid)
        # 登录
        login_data={
        "username":"admin",
        "password":"HM_2023_test",
        "code":"2",
        "uuid":uuid
        }
        res_l=self.login_api.login(test_data=login_data)
        print(res_l.json())
        print(res_l.status_code)

        TestContractBusiness.token=res_l.json().get("token")
    # 2 课程添加
    def test02_add_course_success(self):
        add_course_data = {
            "name": "测试开发课程1",
            "subject": "6",
            "price": 899,
            "applicablePerson": "2",
            "info": "测试开发提升课程，适合有基础的人学习"
        }

        res_add_course = self.course_api.add_course(test_data=add_course_data, token=TestContractBusiness.token)
        print(res_add_course.status_code)
        print(res_add_course.text)
        TestContractBusiness.courseId=res_add_course.json()["data"]["id"]
        # 3上传合同
    def test03_upload_contract(self):
        f=open(config.BASIC_PATH+"/data/1.pdf","rb")
        res_add_contract=self.contract_api.upload_contract(test_data=f,token=TestContractBusiness.token)
        print(res_add_contract.json())
        TestContractBusiness.filename=res_add_contract.json()["fileName"]
        # 4新增合同
    def test04_add_contract(self):
        add_contract_data={
        "name":"测试888",
        "phone":"18971002078",
        "contractNo":"202407119",# "contractNo"合同编号要唯一
        "subject":"6",
        "courseId":TestContractBusiness.courseId,
        "channel":"0",
        "activityId":77,
        "fileName":TestContractBusiness.filename
}
        res_add_contract=self.contract_api.add_contract(test_data=add_contract_data,token=TestContractBusiness.token)
        print(res_add_contract.text)

